Skip to content

refactor(rivetkit-core): rename StopReason to ShutdownKind and kill enum fallthroughs#4765

Draft
NathanFlurry wants to merge 1 commit intosleep-cleanup/11-info-log-envoy-commands-eventsfrom
sleep-cleanup/17-stop-reason-and-fallthrough-fix
Draft

refactor(rivetkit-core): rename StopReason to ShutdownKind and kill enum fallthroughs#4765
NathanFlurry wants to merge 1 commit intosleep-cleanup/11-info-log-envoy-commands-eventsfrom
sleep-cleanup/17-stop-reason-and-fallthrough-fix

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

This was referenced Apr 24, 2026
Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 24, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude Bot commented Apr 24, 2026

Code Review

Overview

This PR does two things: renames StopReasonShutdownKind across rivetkit-core, and eliminates all _ => fallthrough arms on enums (codifying the rule in CLAUDE.md). It's clean, well-scoped, and contains one embedded behavioral fix worth calling out explicitly.


Embedded Bug Fix (Behavioral Change)

The most important change is in map_envoy_stop_reason() in registry/mod.rs:

Old behavior:

let task_stop_reason = match reason {
    protocol::StopActorReason::SleepIntent => StopReason::Sleep,
    _ => StopReason::Destroy,  // GoingAway and Lost were treated as Destroy!
};

New behavior:

protocol::StopActorReason::GoingAway => ShutdownKind::Sleep,  // reallocation
protocol::StopActorReason::Lost      => ShutdownKind::Sleep,  // resurrection

This is correct: GoingAway (runner drain) and Lost (connection drop) are ephemeral restarts where the actor resurfaces with the same identity, so they should run onSleep semantics and preserve durable state — not fire onDestroy and wipe it. The old _ => fallthrough was silently causing permanent destroy semantics for what are actually transient evictions. Worth highlighting explicitly in the PR description since it's a behavioral change wrapped inside a refactor.


Code Quality

Positives:

  • Rename is complete and consistent across all files, public re-exports, test fixtures, and NAPI bindings.
  • Extracted map_envoy_stop_reason() is well-documented. The inline comments on each arm explain the WHY (reallocation vs. permanent destroy), which is genuinely non-obvious.
  • The LifecycleCommand::stop_reason() fallthrough fix correctly enumerates Start and FireAlarm — if a future variant is added the compiler will catch the gap immediately.
  • The try_on_activity() fix is good. The comment explaining why Loading | SleepFinalize | Destroying | Terminated silently drop activity signals is justified (non-obvious constraint) and well-written.
  • Added ?task_stop_reason to the stop-actor log line — nice diagnostic addition.
  • Test coverage: every test call site is updated, no tests were deleted.

Minor suggestions:

  1. map_envoy_stop_reason parameter typeprotocol::StopActorReason is probably Copy. Taking &reason is fine but slightly inconsistent with how the rest of the codebase passes enum values directly. Consider reason: protocol::StopActorReason (by value) to match the pattern used in shutdown_reason_label(reason: ShutdownKind).

  2. ShutdownKind::ALL constantmetrics.rs uses a hardcoded array [ShutdownKind::Sleep, ShutdownKind::Destroy] to pre-register Prometheus labels. StateMutationReason has an ALL const for this purpose. Not a blocker, but worth adding to ShutdownKind for consistency so the metrics init and the enum stay in sync automatically.

  3. PR description — The checklist is unfilled and the description is the default template. Since this does include a real behavioral fix (GoingAway/Lost semantics), a one-line summary of that change in the description would help reviewers and the git history.


Verdict

Approve with the minor notes above. The rename improves readability, the fallthrough elimination is the right call per the new CLAUDE.md rule, and the GoingAway/Lost fix is a genuine correctness improvement that was only visible because of the explicit enum matching.

@github-actions
Copy link
Copy Markdown
Contributor

Preview packages published to npm

Install with:

npm install rivetkit@pr-4765

All packages published as 0.0.0-pr.4765.eff8bc0 with tag pr-4765.

Engine binary is shipped via @rivetkit/engine-cli on linux-x64-musl, linux-arm64-musl, darwin-x64, and darwin-arm64. Windows users should use the release installer or set RIVET_ENGINE_BINARY.

Docker images:

docker pull rivetdev/engine:slim-eff8bc0
docker pull rivetdev/engine:full-eff8bc0
Individual packages
npm install rivetkit@pr-4765
npm install @rivetkit/react@pr-4765
npm install @rivetkit/rivetkit-napi@pr-4765
npm install @rivetkit/workflow-engine@pr-4765

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant